package com.hibikiluler.javalearning.mapper;

import com.github.pagehelper.Page;
import com.hibikiluler.javalearning.entity.Learn;
import com.hibikiluler.javalearning.entity.WxRun;
import org.apache.ibatis.annotations.*;

import java.util.List;

/**
 * @Author
 * @create 2021-12-09 20:24
 */
public interface LearnMapper {

    /**
     * 添加
     * @param learn
     */
    @Insert("insert into learning_information(title, content, create_time, create_name,writer) values (#{title}, #{content}, #{createTime}, #{createName}, #{writer})")
    void insert(Learn learn);

    /**
     * 删除
     * @param id
     */
    void delete(Long id);

    @Delete("delete from learning_information where del=1")
    void clear();

    /**
     * 删除
     * @param id
     */
    Learn findInfo(Long id);

    /**
     * 修改
     * @param learn
     */
    void update(Learn learn);

    /**
     * 分页查询
     * @param queryString
     * @return
     */
    Page<Learn> findPage(String queryString);

    /**
     *  通过userid查找自己发布的资讯  2023.05.13 这里直接根据username去查找就行了
     * @param username
     * @return
     */
    @Select("select * from learning_information where create_name = #{username} and del=0")
    Page<Learn> findByUserName(String username);

    /**
     * 添加微信运动步数
     * @param runs
     */
    void insertStep(@Param("runs") List<WxRun> runs);

    /**
     * 添加微信运动步数
     * @param openid 用户唯一标志
     * @param time 时间
     */
    @Select("select * from wx_run where openid=#{openid} and time=#{time}")
    WxRun findStepByTime(@Param("openid") String openid, @Param("time") String time);

    @Update("update wx_run set step=#{step} where openid=#{openid} and time=#{time}")
    void updateStep(@Param("openid") String openid, @Param("time") String time, @Param("step") Integer step);

    @Select("select * from wx_run where openid=#{openid} and (time<=#{beginTime} and time>=#{endTime})")
    List<WxRun> findByTime(@Param("beginTime") String dateTime, @Param("endTime") String date1, @Param("openid") String openId);


}



